import { createRouter, createWebHistory } from 'vue-router';
import AdminHome from '../views/Admin/AdminHome.vue'



const routes = [
  {
    path: '/',
    redirect: '/adminHome' // 默认跳转到登录页
  },
 
  //admin页面1
  {
    path:'/adminHome',
    name:'AdminHome',
    component:AdminHome
  },

  
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 添加全局导航守卫
router.beforeEach((to, from, next) => {
  const isLoggedIn = localStorage.getItem('isLoggedIn');
  if (to.meta.requiresAuth && !isLoggedIn) {
    // 需要登录的页面，且未登录，则跳转到登录页
    next('/login');
  } else {
    next();
  }
});

export default router;